package rexsee.core.style;

import java.lang.reflect.Field;

import rexsee.core.utilities.Utilities;
import android.content.Context;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Build.VERSION;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;

public class StyleSheet {

	public String styleText = "";

	//For position of buttonBars, tabBars, etc.
	public String bar_position = "top"; //top|bottom|browser|layout
	public String index = "-1"; //>0 means forward, 0 is first; <0 means backward, -1 is last

	//progressDialog, for RexseeBrowser
	public String browser_progress_dialog = "visible"; //visible|hidden
	public String browser_zoom_button = "hidden"; //visible|hidden

	//For Dialog
	public String window_type = "context"; //context|popup
	public String window_split_screen = "false"; //true|false
	public String window_show_wallpaper = "false"; //true|false
	public String window_modeless = "false"; //true|false
	public String window_blur_behind = "false"; //true|false
	public String window_dim_amount = "0.5"; //float
	public String window_style = "transparent"; //dark|light|transparent
	public String window_animation = "dialog"; //inputmethod|translucent|activity|dialog|toast|none
	public String window_moveable = "false"; //true|false
	public String window_cancelable = "true"; //true|false
	public String window_outside_cancelable = "false"; //true|false
	public String window_align = "left"; //left|center|right
	public String window_vertical_align = "top"; //top|middle|bottom
	public String window_auto_hide = "-1"; //int, number of seconds, -1 means infinite
	public String window_fullscreen = "normal"; //normal|fullscreen
	public String top = "0";
	public String left = "0";
	public String alpha = "0.9";

	//layout, for Div
	public String visibility = "visible"; //visible|hidden|gone
	public String inner_visibility = "visible"; //visible|hidden
	public String position = "static"; //static|absolute|relative|table
	public String width = "fillparent"; //wrap-content|fill-parent|int
	public String min_width = "0"; //int * 
	public String height = "fillparent"; //wrap-content|fill-parent|int
	public String min_height = "0"; //int 
	public String weight = "0"; //int
	public String background_color = "#888888"; //String|gradientDrawable

	public String border_color = ""; //Shortcut
	public String border_left_color = "#AAAAAA"; //String|gradientDrawable
	public String border_top_color = "#AAAAAA"; //String|gradientDrawable
	public String border_right_color = "#AAAAAA"; //String|gradientDrawable
	public String border_bottom_color = "#AAAAAA"; //String|gradientDrawable

	public String border_width = ""; //Shortcut
	public String border_left_width = "1"; //int
	public String border_top_width = "1"; //int
	public String border_right_width = "1"; //int
	public String border_bottom_width = "1"; //int

	public String border_scale = ""; //Shortcut 
	public String border_left_scale = "inside"; //center|crop|inside|fitcenter|fitstart|fitend|fitxy
	public String border_top_scale = "inside"; //center|crop|inside|fitcenter|fitstart|fitend|fitxy
	public String border_right_scale = "inside"; //center|crop|inside|fitcenter|fitstart|fitend|fitxy 
	public String border_bottom_scale = "inside"; //center|crop|inside|fitcenter|fitstart|fitend|fitxy 

	public String border_alpha = "1"; //Shortcut 
	public String border_left_alpha = "1"; //0~1
	public String border_top_alpha = "1"; //0~1
	public String border_right_alpha = "1"; //0~1
	public String border_bottom_alpha = "1"; //0~1

	public String margin = ""; //Shortcut
	public String margin_left = "0"; //int
	public String margin_top = "0"; //int
	public String margin_right = "0"; //int
	public String margin_bottom = "0"; //int
	public String margin_background = "sameasforeground"; //Shortcut

	public String padding = ""; //Shortcut
	public String padding_left = "0"; //int
	public String padding_top = "0"; //int
	public String padding_right = "0"; //int
	public String padding_bottom = "0"; //int

	public String orientation = "x"; //x|y or horizontal|vertical
	public String align = "center"; //left|center|right
	public String vertical_align = "middle"; //top|middle|bottom

	public String overflow = ""; //Shortcut
	public String overflow_x = "hidden"; //hidden|visible
	public String overflow_y = "hidden"; //hidden|visible

	public String scrollbar = ""; //Shortcut
	public String scrollbar_x = "hidden"; //visible|auto|hidden
	public String scrollbar_y = "hidden"; //visible|auto|hidden

	public String scrollbar_style = ""; //Shortcut
	public String scrollbar_x_style = "inside"; //inside|outside|insideinset|outsideinset
	public String scrollbar_y_style = "inside"; //inside|outside|insideinset|outsideinset

	public String fading_edge_length = ""; //Shortcut
	public String fading_edge_x_length = "0";
	public String fading_edge_y_length = "0";

	public String fading_edge_color = ""; //Shortcut
	public String fading_edge_x_color = "#444444";
	public String fading_edge_y_color = "#444444";

	public String play_sound_effect = "false"; // true|false 

	//icon, for Label
	public Drawable icon = null; //Drawable
	public String icon_url = ""; //String
	public String icon_position = "top"; //top|bottom|left|right
	public String icon_visibility = "visible"; //visible|hidden
	public String icon_scale = "inside"; //center|crop|inside|fitcenter|fitstart|fitend|fitxy 
	public String icon_width = "24"; //int
	public String icon_height = "24"; //int
	public String icon_weight = "0"; //int
	public String icon_padding = ""; //Shortcut 
	public String icon_padding_left = "0"; //int 
	public String icon_padding_top = "0"; //int 
	public String icon_padding_right = "0"; //int 
	public String icon_padding_bottom = "0"; //int 
	public String icon_background_color = "transparent"; //String|gradientDrawable
	public String icon_alpha = "1";
	public String icon_bounds = "-1";

	//label, for Label
	public String label = ""; //String
	public String label_type = "string"; //html|string|text
	public String label_visibility = "visible"; //visible|hidden
	public String label_width = "fillparent"; //int
	public String label_height = "fillparent"; //int
	public String label_weight = "0"; //int
	public String label_padding = ""; //Shortcut
	public String label_padding_left = "0"; //int
	public String label_padding_top = "0"; //int
	public String label_padding_right = "0"; //int
	public String label_padding_bottom = "0"; //int
	public String label_background_color = "transparent"; //String|gradientDrawable
	public String color = "#FFFFFF"; //String|int
	public String font_size = "14"; //float
	public String font_weight = "normal"; //normal|bold
	public String font_style = "normal"; //normal|italic
	public String text_decoration = "normal"; //normal|underline|strikethru *native
	public String text_shadow = ""; //Shortcut
	public String text_shadow_radius = "0"; //float
	public String text_shadow_dx = "0"; //float
	public String text_shadow_dy = "0"; //float
	public String text_shadow_color = "#000000"; //String|int
	public String text_link = "true"; //true|false
	public String text_align = "center"; //left|center|right
	public String text_vertical_align = "middle"; //top|middle|bottom
	public String text_overflow = "none"; //none|marquee|start|middle|end
	public String white_space = "nowrap"; //normal|nowrap
	public String line_height = "100%"; //float

	//for pageFlip
	public String horizontal_line = "false"; //true|false 

	//for edittext
	public String selectall = "false"; // true|false
	public String maxlength = "0"; // Integer 
	public String hint = ""; // String 
	public String hint_color = "#888888"; // String 

	//for progressBar 
	public String progress = "0%";
	public String progress_color = "#FDC913"; //String|gradientDrawable
	public String progress_text_color = "#000000"; //String
	public String rating_stars = "5"; //int 
	public String rating_step = "0.5"; //int 

	//for Natives
	public String format = ""; //TimePicker|Chronometer|SurfaceView|GridView|EditText(text|number|decimal|signed|phone|password|email|url) 
	public String mode = ""; // ProgressBar|RatingBar|ListView|GridView|Gallery|VideoView|SurfaceView 
	public String key = ""; // Advertisement 
	public String path = ""; //VideoView|PageView
	public String duration = "1000"; //milliseconds 
	public String column_span = "1"; //TableLayout 
	public String column_number = "0"; //GridView int 
	public String column_width = "100"; //GridView int 
	public String horizontal_spacing = "0"; //GridView|Gallery int 
	public String vertical_spacing = "0"; //GridView|ListView int 
	public String effect = "false"; //Gallery(reflectshader)
	public String enable = "true"; //

	public String distance_threshold = "0"; //ImageDialog|Gallery|ThreeDGallery int 
	public String zoom = "0"; //ThreeDGallery int 
	public String zoom_reverse = "true"; //ThreeDGallery int 
	public String rotation = "60"; //ThreeDGallery int 
	public String rotation_reverse = "false"; //ThreeDGallery int 

	public String event_touch = "false"; //
	public String event_touchmove = "false"; //
	public String event_multitouch = "false"; //
	public String event_scroll = "false"; //

	public final Context mContext;
	private final float mDensity;
	public int scale(int pixel) {
		return Math.round(mDensity * pixel);
	}
	private String[] split(String value, int n) {
		if (n <= 0) return null;
		String[] rtn = new String[n];
		String[] v = value.split("\\ ");
		rtn[0] = v[0];
		for (int i = 1; i < n; i++) {
			if (v.length > i) rtn[i] = v[i];
			else rtn[i] = rtn[i - 1];
		}
		return rtn;
	}
	public static ScaleType getScaleType(String scaleType) {
		if (scaleType.equalsIgnoreCase("fitcenter")) return ScaleType.FIT_CENTER;
		else if (scaleType.equalsIgnoreCase("fitstart")) return ScaleType.FIT_START;
		else if (scaleType.equalsIgnoreCase("fitend")) return ScaleType.FIT_END;
		else if (scaleType.equalsIgnoreCase("fitxy")) return ScaleType.FIT_XY;
		else if (scaleType.equalsIgnoreCase("center")) return ScaleType.CENTER;
		else if (scaleType.equalsIgnoreCase("crop")) return ScaleType.CENTER_CROP;
		else if (scaleType.equalsIgnoreCase("inside")) return ScaleType.CENTER_INSIDE;
		else return ScaleType.CENTER_INSIDE;
	}
	public static int getImageAlpha(String sAlpha) {
		float rtn = Utilities.getFloat(sAlpha, 0);
		if (rtn >= 1) return 255;
		else if (rtn <= 0) return 0;
		else return Math.round(rtn * 255f);
	}

	public StyleSheet(Context context) {
		mContext = context;
		mDensity = context.getResources().getDisplayMetrics().density;
	}

	public StyleSheet parseStyle(String style) {
		if (style == null || style.equals("")) return this;
		styleText = style;
		String[] argus = style.split(";");
		for (int i = 0; i < argus.length; i++) {
			if (argus[i].indexOf(":") <= 0) continue;
			String key = argus[i].substring(0, argus[i].indexOf(":")).trim().toLowerCase().replaceAll("\\-", "\\_");
			String value = argus[i].substring(argus[i].indexOf(":") + 1).trim();
			if (value.length() == 0) continue;
			if (key.equals("icon")) {
				icon_url = value;
			} else if (key.equals("border_color")) {
				String[] tmp = split(value, 4);
				border_top_color = tmp[0];
				border_right_color = tmp[1];
				border_bottom_color = tmp[2];
				border_left_color = tmp[3];
			} else if (key.equals("border_width")) {
				String[] tmp = split(value, 4);
				border_top_width = tmp[0];
				border_right_width = tmp[1];
				border_bottom_width = tmp[2];
				border_left_width = tmp[3];
			} else if (key.equals("border_scale")) {
				String[] tmp = split(value, 4);
				border_top_scale = tmp[0];
				border_right_scale = tmp[1];
				border_bottom_scale = tmp[2];
				border_left_scale = tmp[3];
			} else if (key.equals("border_alpha")) {
				String[] tmp = split(value, 4);
				border_top_alpha = tmp[0];
				border_right_alpha = tmp[1];
				border_bottom_alpha = tmp[2];
				border_left_alpha = tmp[3];
			} else if (key.equals("margin")) {
				String[] tmp = split(value, 4);
				margin_top = tmp[0];
				margin_right = tmp[1];
				margin_bottom = tmp[2];
				margin_left = tmp[3];
			} else if (key.equals("padding")) {
				String[] tmp = split(value, 4);
				padding_top = tmp[0];
				padding_right = tmp[1];
				padding_bottom = tmp[2];
				padding_left = tmp[3];
			} else if (key.equals("icon_padding")) {
				String[] tmp = split(value, 4);
				icon_padding_top = tmp[0];
				icon_padding_right = tmp[1];
				icon_padding_bottom = tmp[2];
				icon_padding_left = tmp[3];
			} else if (key.equals("label_padding")) {
				String[] tmp = split(value, 4);
				label_padding_top = tmp[0];
				label_padding_right = tmp[1];
				label_padding_bottom = tmp[2];
				label_padding_left = tmp[3];
			} else if (key.equals("text_shadow")) {
				String[] tmp = split(value, 4);
				text_shadow_radius = tmp[0];
				text_shadow_dx = tmp[1];
				text_shadow_dy = tmp[2];
				text_shadow_color = tmp[3];
			} else if (key.equals("overflow")) {
				String[] tmp = split(value, 2);
				overflow_x = tmp[0];
				overflow_y = tmp[1];
			} else if (key.equals("scrollbar")) {
				String[] tmp = split(value, 2);
				scrollbar_x = tmp[0];
				scrollbar_y = tmp[1];
			} else if (key.equals("scrollbar_style")) {
				String[] tmp = split(value, 2);
				scrollbar_x_style = tmp[0];
				scrollbar_y_style = tmp[1];
			} else if (key.equals("fading_edge_length")) {
				String[] tmp = split(value, 2);
				fading_edge_x_length = tmp[0];
				fading_edge_y_length = tmp[1];
			} else if (key.equals("fading_edge_color")) {
				String[] tmp = split(value, 2);
				fading_edge_x_color = tmp[0];
				fading_edge_y_color = tmp[1];
			} else {
				try {
					this.getClass().getField(key).set(this, value);
				} catch (Exception e) {
				}
			}
		}
		if (!this.icon_url.equals("")) {
			this.icon = RexseeDrawable.getDrawable(mContext, null, this.icon_url);
		}
		return this;
	}
	public String getStyle(String name) {
		name = name.replaceAll("\\-", "\\_");
		if (name.equalsIgnoreCase("icon")) {
			return icon_url;
		} else {
			try {
				return (String) this.getClass().getField(name).get(this);
			} catch (Exception e) {
				return null;
			}
		}
	}
	@Override
	public StyleSheet clone() {
		StyleSheet rtn = new StyleSheet(mContext);
		Field[] fields = this.getClass().getFields();
		for (int i = 0; i < fields.length; i++) {
			try {
				fields[i].set(rtn, fields[i].get(this));
			} catch (Exception e) {
			}
		}
		return rtn;
	}

	public int getBorderWidthLeft() {
		return scale(Utilities.getInt(border_left_width.toLowerCase().replaceAll("px", ""), 1));
	}
	public int getBorderWidthRight() {
		return scale(Utilities.getInt(border_right_width.toLowerCase().replaceAll("px", ""), 1));
	}
	public int getBorderWidthTop() {
		return scale(Utilities.getInt(border_top_width.toLowerCase().replaceAll("px", ""), 1));
	}
	public int getBorderWidthBottom() {
		return scale(Utilities.getInt(border_bottom_width.toLowerCase().replaceAll("px", ""), 1));
	}

	public ScaleType getIconScaleType() {
		return getScaleType(icon_scale);
	}

	public int getIconPaddingLeft() {
		return scale(Utilities.getInt(icon_padding_left.toLowerCase().replaceAll("px", ""), 0));
	}
	public int getIconPaddingRight() {
		return scale(Utilities.getInt(icon_padding_right.toLowerCase().replaceAll("px", ""), 0));
	}
	public int getIconPaddingTop() {
		return scale(Utilities.getInt(icon_padding_top.toLowerCase().replaceAll("px", ""), 0));
	}
	public int getIconPaddingBottom() {
		return scale(Utilities.getInt(icon_padding_bottom.toLowerCase().replaceAll("px", ""), 0));
	}

	public int getLabelPaddingLeft() {
		return scale(Utilities.getInt(label_padding_left.toLowerCase().replaceAll("px", ""), 0));
	}
	public int getLabelPaddingRight() {
		return scale(Utilities.getInt(label_padding_right.toLowerCase().replaceAll("px", ""), 0));
	}
	public int getLabelPaddingTop() {
		return scale(Utilities.getInt(label_padding_top.toLowerCase().replaceAll("px", ""), 0));
	}
	public int getLabelPaddingBottom() {
		return scale(Utilities.getInt(label_padding_bottom.toLowerCase().replaceAll("px", ""), 0));
	}

	public int getMarginLeft() {
		return scale(Utilities.getInt(margin_left.toLowerCase().replaceAll("px", ""), 0));
	}
	public int getMarginRight() {
		return scale(Utilities.getInt(margin_right.toLowerCase().replaceAll("px", ""), 0));
	}
	public int getMarginTop() {
		return scale(Utilities.getInt(margin_top.toLowerCase().replaceAll("px", ""), 0));
	}
	public int getMarginBottom() {
		return scale(Utilities.getInt(margin_bottom.toLowerCase().replaceAll("px", ""), 0));
	}

	public int getPaddingLeft() {
		return scale(Utilities.getInt(padding_left.toLowerCase().replaceAll("px", ""), 0));
	}
	public int getPaddingRight() {
		return scale(Utilities.getInt(padding_right.toLowerCase().replaceAll("px", ""), 0));
	}
	public int getPaddingTop() {
		return scale(Utilities.getInt(padding_top.toLowerCase().replaceAll("px", ""), 0));
	}
	public int getPaddingBottom() {
		return scale(Utilities.getInt(padding_bottom.toLowerCase().replaceAll("px", ""), 0));
	}

	public int getColumnWidth() {
		return scale(Utilities.getInt(column_width.toLowerCase().replaceAll("px", ""), 0));
	}
	public int getHorizontalSpacing() {
		return scale(Utilities.getInt(horizontal_spacing.toLowerCase().replaceAll("px", ""), 0));
	}
	public int getVerticalSpacing() {
		return scale(Utilities.getInt(vertical_spacing.toLowerCase().replaceAll("px", ""), 0));
	}

	public int getWindowAnimation() {
		if (window_animation.equalsIgnoreCase("none")) return android.R.style.Animation;
		else if (window_animation.equalsIgnoreCase("right") || window_animation.equalsIgnoreCase("translucent")) return android.R.style.Animation_Translucent;
		else if (window_animation.equalsIgnoreCase("activity")) return android.R.style.Animation_Activity;
		else if (window_animation.equalsIgnoreCase("dialog")) return android.R.style.Animation_Dialog;
		else if (window_animation.equalsIgnoreCase("toast")) return android.R.style.Animation_Toast;
		else if (window_animation.equalsIgnoreCase("bottom") || window_animation.equalsIgnoreCase("inputmethod")) {
			if (Integer.parseInt(VERSION.SDK) >= 5) {
				return 16973910; // android.R.style.Animation_InputMethod, for SDK 5+
			} else {
				return android.R.style.Animation; // No animation, for SDK 5-
			}
		} else return android.R.style.Animation_Dialog;
	}
	public int getWindowStyle() {
		if (window_style.equalsIgnoreCase("dark")) return android.R.drawable.toast_frame;
		else if (window_style.equalsIgnoreCase("light")) return android.R.drawable.alert_light_frame;
		else return 0;
	}
	public int getWindowGravity() {
		int hAlign, vAlign;
		if (window_align.equals("left")) hAlign = Gravity.LEFT;
		else if (window_align.equals("right")) hAlign = Gravity.RIGHT;
		else hAlign = Gravity.CENTER_HORIZONTAL;
		if (window_vertical_align.equals("top")) vAlign = Gravity.TOP;
		else if (window_vertical_align.equals("bottom")) vAlign = Gravity.BOTTOM;
		else vAlign = Gravity.CENTER_VERTICAL;
		return hAlign | vAlign;
	}
	public int getTextGravity() {
		int hAlign, vAlign;
		if (text_align.equals("left")) hAlign = Gravity.LEFT;
		else if (text_align.equals("right")) hAlign = Gravity.RIGHT;
		else hAlign = Gravity.CENTER_HORIZONTAL;
		if (text_vertical_align.equals("top")) vAlign = Gravity.TOP;
		else if (text_vertical_align.equals("bottom")) vAlign = Gravity.BOTTOM;
		else vAlign = Gravity.CENTER_VERTICAL;
		return hAlign | vAlign;
	}
	public int getGravity() {
		int hAlign, vAlign;
		if (align.equals("left")) hAlign = Gravity.LEFT;
		else if (align.equals("right")) hAlign = Gravity.RIGHT;
		else hAlign = Gravity.CENTER_HORIZONTAL;
		if (vertical_align.equals("top")) vAlign = Gravity.TOP;
		else if (vertical_align.equals("bottom")) vAlign = Gravity.BOTTOM;
		else vAlign = Gravity.CENTER_VERTICAL;
		return hAlign | vAlign;
	}
	public int getTypefaceStyle() {
		int bold = font_weight.equalsIgnoreCase("bold") ? Typeface.BOLD : Typeface.NORMAL;
		int italic = font_style.equalsIgnoreCase("italic") ? Typeface.ITALIC : Typeface.NORMAL;
		return bold | italic;
	}
	public int getScrollbarXStyle() {
		if (scrollbar_x_style.equalsIgnoreCase("outside")) return View.SCROLLBARS_OUTSIDE_OVERLAY;
		else if (scrollbar_x_style.equalsIgnoreCase("insideinset")) return View.SCROLLBARS_INSIDE_INSET;
		else if (scrollbar_x_style.equalsIgnoreCase("outsideinset")) return View.SCROLLBARS_OUTSIDE_INSET;
		else return View.SCROLLBARS_INSIDE_OVERLAY;
	}
	public int getScrollbarYStyle() {
		if (scrollbar_y_style.equalsIgnoreCase("outside")) return View.SCROLLBARS_OUTSIDE_OVERLAY;
		else if (scrollbar_y_style.equalsIgnoreCase("insideinset")) return View.SCROLLBARS_INSIDE_INSET;
		else if (scrollbar_y_style.equalsIgnoreCase("outsideinset")) return View.SCROLLBARS_OUTSIDE_INSET;
		else return View.SCROLLBARS_INSIDE_OVERLAY;
	}
	public float getAlpha() {
		float rtn = Utilities.getFloat(alpha, 0);
		if (rtn > 1) return 1;
		else if (rtn < 0) return 0;
		else return rtn;
	}
	public int getIconAlpha() {
		return getImageAlpha(icon_alpha);
	}
	public int getTop() {
		return scale(Utilities.getInt(top.toLowerCase().replaceAll("px", ""), 0));
	}
	public int getLeft() {
		return scale(Utilities.getInt(left.toLowerCase().replaceAll("px", ""), 0));
	}
	public int getWidth() {
		if (width.equalsIgnoreCase("wrapcontent")) return LinearLayout.LayoutParams.WRAP_CONTENT;
		else if (width.equalsIgnoreCase("fillparent") || width.equalsIgnoreCase("100%")) return LinearLayout.LayoutParams.FILL_PARENT;
		else return scale(Utilities.getInt(width.toLowerCase().replaceAll("px", ""), 24));
	}
	public int getHeight() {
		if (height.equalsIgnoreCase("wrapcontent")) return LinearLayout.LayoutParams.WRAP_CONTENT;
		else if (height.equalsIgnoreCase("fillparent") || height.equalsIgnoreCase("100%")) return LinearLayout.LayoutParams.FILL_PARENT;
		else return scale(Utilities.getInt(height.toLowerCase().replaceAll("px", ""), 24));
	}
	public LinearLayout.LayoutParams getLayoutParams() {
		int wgt = Utilities.getInt(weight, 0);
		if (wgt <= 0) return new LinearLayout.LayoutParams(getWidth(), getHeight());
		else return new LinearLayout.LayoutParams(getWidth(), getHeight(), wgt);

	}
	public int getIconWidth() {
		if (icon_width.equalsIgnoreCase("wrapcontent")) return LinearLayout.LayoutParams.WRAP_CONTENT;
		else if (icon_width.equalsIgnoreCase("fillparent")) return LinearLayout.LayoutParams.FILL_PARENT;
		else if (icon_width.equalsIgnoreCase("keepscale")) return -3;
		else return scale(Utilities.getInt(icon_width.toLowerCase().replaceAll("px", ""), 24));
	}
	public int getIconHeight() {
		if (icon_height.equalsIgnoreCase("wrapcontent")) return LinearLayout.LayoutParams.WRAP_CONTENT;
		else if (icon_height.equalsIgnoreCase("fillparent")) return LinearLayout.LayoutParams.FILL_PARENT;
		else if (icon_height.equalsIgnoreCase("keepscale")) return -3;
		else return scale(Utilities.getInt(icon_height.toLowerCase().replaceAll("px", ""), 24));
	}
	public LinearLayout.LayoutParams getIconLayoutParams(int bitmapWidth, int bitmapHeight, int viewWidth, int viewHeight) {
		int mWidth = getIconWidth(), mHeight = getIconHeight();
		if (mWidth == -3 && mHeight == -3) {
			return new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
		} else if (mWidth == -3) {
			if (mHeight == LinearLayout.LayoutParams.WRAP_CONTENT) {
				return new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
			} else if (mHeight == LinearLayout.LayoutParams.FILL_PARENT) {
				mWidth = Math.round(viewHeight * (float) bitmapWidth / bitmapHeight);
				return new LinearLayout.LayoutParams(mWidth, mHeight);
			} else {
				mWidth = Math.round(mHeight * (float) bitmapWidth / bitmapHeight);
				return new LinearLayout.LayoutParams(mWidth, mHeight);
			}
		} else if (mHeight == -3) {
			if (mWidth == LinearLayout.LayoutParams.WRAP_CONTENT) {
				return new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
			} else if (mWidth == LinearLayout.LayoutParams.FILL_PARENT) {
				mHeight = Math.round(viewWidth * (float) bitmapHeight / bitmapWidth);
				return new LinearLayout.LayoutParams(mWidth, mHeight);
			} else {
				mHeight = Math.round(mWidth * (float) bitmapHeight / bitmapWidth);
				return new LinearLayout.LayoutParams(mWidth, mHeight);
			}
		} else {
			return getIconLayoutParams();
		}
	}
	public LinearLayout.LayoutParams getIconLayoutParams() {
		int mWidth = getIconWidth(), mHeight = getIconHeight(), mWeight = Utilities.getInt(icon_weight, 0);
		if (mWeight <= 0) return new LinearLayout.LayoutParams(mWidth, mHeight);
		else return new LinearLayout.LayoutParams(mWidth, mHeight, mWeight);
	}
	public LinearLayout.LayoutParams getLabelLayoutParams() {
		int mWidth, mHeight, mWeight;
		if (label_width.equalsIgnoreCase("wrapcontent")) mWidth = LinearLayout.LayoutParams.WRAP_CONTENT;
		else if (label_width.equalsIgnoreCase("fillparent")) mWidth = LinearLayout.LayoutParams.FILL_PARENT;
		else mWidth = scale(Utilities.getInt(label_width.toLowerCase().replaceAll("px", ""), 24));
		if (label_height.equalsIgnoreCase("wrapcontent")) mHeight = LinearLayout.LayoutParams.WRAP_CONTENT;
		else if (label_height.equalsIgnoreCase("fillparent")) mHeight = LinearLayout.LayoutParams.FILL_PARENT;
		else mHeight = scale(Utilities.getInt(label_height.toLowerCase().replaceAll("px", ""), 24));
		mWeight = Utilities.getInt(label_weight, 0);
		if (mWeight <= 0) return new LinearLayout.LayoutParams(mWidth, mHeight);
		else return new LinearLayout.LayoutParams(mWidth, mHeight, mWeight);

	}

	public void destroy() {
	}
}
